
import TheConstant from './TheConstant';
import TheNumber from './TheNumber';
import TheLetter from './TheLetter';
import TheSymbol from './TheSymbol';
import TheCombo from './TheCombo';
import TheChoice from './TheChoice';
import ThePublic from './ThePublic';
import TheCandidate from './TheCandidate';
import TheHandWriter from './TheHandWriter';
import ChineseSyllable from './ChineseSyllable';

class KeepPress {
    constructor () {
        this.timeout = null;
        this.pressDate = null;
        this.wait = null;
        this.triggerClick = true;
    }

    down (fn, wait) {
        let self = this;
        this.wait = wait;
        return function (...rest) {
            this.triggerClick = true;
            self.pressDate = new Date();
            self.timeout = setTimeout(() => {
                fn.apply(this, rest);
            }, wait);
        };
    }

    up (fn) {
        let self = this;
        return function (...rest) {
            self.triggerClick = false;
            clearTimeout(self.timeout);
            if (new Date() - self.pressDate < self.wait) {
                fn.apply(this, rest);
            }
        };
    }

    click (fn) {
        let self = this;
        return function (...rest) {
            self.triggerClick && fn.apply(this, rest);
            self.triggerClick = true;
        };
    }
}
export default {
    TheConstant,
    TheNumber,
    TheLetter,
    TheSymbol,
    TheCombo,
    TheChoice,
    ThePublic,
    TheCandidate,
    TheHandWriter,
    ChineseSyllable,
};
export {
    KeepPress,
};
